#[macro_use(quick_error)] extern crate quick_error;

mod lexer;
mod parser;
mod cobol;
mod render;
mod field;
mod group;
mod spec;
mod test;

pub use cobol::{
    DecimalFormat,
    DecimalSpec,
    Field,
    Group,
    Record,
    Sign,
    Spec,
    RecordLike,
    StringSpec};

pub use parser::{Parser, TokenStream};
pub use lexer::tokenize;
pub use render::render_module; 

pub type Result<T> = std::result::Result<T, Error>;

quick_error! {
    #[derive(Debug)]
    pub enum Error {
        ParseError {
            msg: String,
            col: u32,
            row: u32,
        }
        ReadError(e: std::io::Error){ 
            from()
        }
        ParseIntError(e: std::num::ParseIntError){
            from()
        }
        Utf8Error(e: std::str::Utf8Error) {
            from()
        }
        FromUtf8Error(e: std::string::FromUtf8Error){
            from()
        }
        WrongFieldType {
            name: String,
            expected: String,
            actual: String,
        }
        DecimalConvertError(e: rust_decimal::Error) {
            from()
        }
        AccessNumberFieldError {
            bytes: Vec<u8>, 
        }
        ClauseNotSupported {
            clause: String
        }
        BufferTooShort{
            expected: usize,
            actual: usize,
        }
        TeraError(e: tera::Error) {
            from()
        }
    }
}
